<?php 
namespace lib;
class XFDB{
    public static function userrow($value , $name = 'user'){
        $sql = "SELECT * FROM pay_user WHERE `".$name."`=:value LIMIT 1";
        $params = ['value' => $value];
        $userrow = safeSqlQuery($sql, $params)['result'][0];
        return $userrow;
    }
    public static function config($k){
        $sql = "SELECT * FROM pay_config WHERE `k`=:k LIMIT 1";
         $params = ['k' => $k];
         return safeSqlQuery($sql, $params)['result'][0];
    }
    public static function wxyunurllist(){
         $get = input("get");
         $type = $get['type'];
	     $msg = $get['msg'];
         $where = [];
        $params = [];
        if (!empty($type) &&  !empty($msg)){
            if ($type == 'url'){
                 $where[] = "`$type` = :msg";
                 $params['msg'] = $msg;
            }
        }
         $whereClause = !empty($where) ? "WHERE " . implode(" AND ", $where) : "";
          $sql_count = "SELECT COUNT(*) AS count FROM pay_wxyunurl  $whereClause";
         $count_result = safeSqlQuery($sql_count, $params, 'select');
         $getCount = $count_result['result'][0]['count'];
         
         $pagesize = $get['limit'];
         $pages = ceil($getCount / $pagesize);
         $page = isset($get['page']) ? intval($get['page']) : 1;
         $offset = $pagesize * ($page - 1);
        // 构建 SQL 查询
         $sql = "SELECT * FROM pay_wxyunurl $whereClause ORDER BY id DESC LIMIT {$offset}, {$pagesize}";
         $result = safeSqlQuery($sql, $params, 'select');
         
         $data = $result['result'];
         foreach ($data as &$res){
             $res['code'] = ($res['code'] == 1)?'MAC':'UOS';
         }
         return ['count'=>$getCount,"data"=>$data];
     
    }
    public static function wxyunurlall(){
         $sql = "SELECT * FROM `pay_wxyunurl` WHERE `status`='1'";
         return safeSqlQuery($sql, $params);
    }
    public static function wxyunurlrow($value,$name = 'id'){
        $sql = "SELECT * FROM `pay_wxyunurl` WHERE `".$name."`=:value LIMIT 1";
       
        $params = ['value' => $value];
        $userrow = safeSqlQuery($sql, $params)['result'][0];
        return $userrow;
    }
    public static function qrlistrow($value,$name = 'id'){
        $sql = "SELECT * FROM `pay_qrlist` WHERE `".$name."`=:value LIMIT 1";
        $params = ['value' => $value];
        $row    = safeSqlQuery($sql, $params)['result'][0];
        return $row;
    }
}

?>